home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / smail-3.1.28 / util / checkerr.sh next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  1992-09-20  |  4.8 KB  |  175 lines

  1. #!/bin/sh
  2. # @(#)util/checkerr.sh    1.6 9/20/92 12:55:08
  3. #
  4. #    Copyright (C) 1987, 1988 Ronald S. Karr and Landon Curt Noll
  5. #    Copyright (C) 1992  Ronald S. Karr
  6. # See the file COPYING, distributed with smail, for restriction
  7. # and warranty information.
  8.  
  9. # Check for errors which have been deposited in the smail error directory.
  10. # If any new messages are found in this directory, save information
  11. # related to those errors in the file .checkerror which is then mailed
  12. # to the postmaster.  If the mail cannot be sent to the postmaster now,
  13. # such as due to a configuration error, then try to send it in a future
  14. # invocation of this script.
  15.  
  16. PATH="X_SECURE_PATH_X"; export PATH
  17. SMAIL_PROGRAM="X_SMAIL_NAME_X"
  18. SPOOL_DIRS="`$SMAIL_PROGRAM -bP spool_dirs`"
  19. HOSTNAME="`$SMAIL_PROGRAM -bP primary_name`"
  20. LOGFILE="`$SMAIL_PROGRAM -bP logfile`"
  21. OLD_LOGFILE="`echo $LOGFILE | sed -e 's,^\(.*\)/\([^/][^/]*\)$,\1/OLD/\2,'`"
  22. PANICLOG="`$SMAIL_PROGRAM -bP paniclog`"
  23. OLD_PANICLOG="`echo $PANICLOG | sed -e 's,^\(.*\)/\([^/][^/]*\)$,\1/OLD/\2,'`"
  24. Z_DOT="X_DOT_Z_X"
  25. ZCAT="X_ZCAT_X"
  26. PROG=$0
  27.  
  28. # go into each spooling directory
  29. (IFS=:; for i in $SPOOL_DIRS; do echo $i; done) |
  30. while read SPOOLDIR; do
  31.     cd $SPOOLDIR
  32.     if [ $? != 0 ]; then
  33.     # spool directory did not exist, ignore it
  34.     continue
  35.     fi
  36.  
  37.     # cleanup old msg.* files in the input directory
  38.     if [ -d input ]; then
  39.     find input -name 'msg.*' -mtime +2 -print | while read fn
  40.     do
  41.         rm -f "$fn"
  42.     done
  43.     fi
  44.  
  45.     # cleanup msglog files with no corresponding input or error file:
  46.     if [ -d msglog ]; then (
  47.         cd msglog
  48.     x="`echo [0-9]*`"
  49.     sleep 1            # avoids an almost impossible race condition
  50.     if [ "$x" != "[0-9]*" ]; then
  51.         for i in $x; do
  52.         if [ ! -f ../input/$i ] && [ ! -f ../error/$i ]; then
  53.             rm -f $i
  54.         fi
  55.         done
  56.     fi
  57.     ); fi
  58.  
  59.     # if the last run found some errors, but couldn't deliver, try again now
  60.     if [ -s .checkerror ]; then
  61.     # don't send to the Postmaster if configuration errors still exist
  62.     x="`$SMAIL_PROGRAM -bv Postmaster 2>/dev/null`"
  63.     if [ "$x" ]; then
  64.         $SMAIL_PROGRAM -f"<+>" -eq -m Postmaster <<EOF
  65. From: MAILER-DAEMON
  66. Subject: Mail errors on the host $HOSTNAME
  67.  
  68. Smail has detected new errors requiring your attention on the
  69. host $HOSTNAME.  Messages which failed can be found in the
  70. directory $SPOOLDIR/error and should be moved back to
  71. $SPOOLDIR when the situation which caused the error has
  72. been taken care of.
  73.  
  74. A sumary of these errors follows:
  75. `cat .checkerror`
  76. EOF
  77.         if [ $? -ne 0 ]; then
  78.         continue
  79.         fi
  80.         rm -f .checkerror
  81.     else
  82.         # if we cannot reach the postmaster, don't go to the next step
  83.         continue
  84.     fi
  85.     fi
  86.  
  87.     if [ ! -d error ]; then
  88.     # no error directory, so there could not be new errors
  89.     continue
  90.     fi
  91.  
  92.     # find any new errors
  93.     if [ -f .lasttimedone ]; then
  94.     mv -f .lasttimedone .thistime
  95.     : > .lasttimedone
  96.     cd error; find * -newer ../.thistime -name '[0-9]*' -print
  97.     else
  98.     : > .lasttimedone
  99.     cd error; find * -name '[0-9]*' -print
  100.     fi 2> /dev/null | while read f; do
  101.     echo ""; echo "------------------ Message $f ------------------"
  102.     if [ -s msglog/$f ]; then
  103.         echo "The per-message log file contains:"
  104.         sed 's/^/ /' < msglog/$f
  105.     else
  106.         echo "No per-message log file was created"
  107.     fi
  108.     echo ""; echo "Logfile entries related to this message are:"
  109.     (if [ -f $LOGFILE ]; then
  110.         cat $LOGFILE;
  111.      fi
  112.      if [ -f $OLD_LOGFILE.0 ]; then
  113.         cat $OLD_LOGFILE.0;
  114.      elif [ -f $OLD_LOGFILE.0$Z_DOT ]; then
  115.         $ZCAT $OLD_LOGFILE.0$Z_DOT;
  116.      fi
  117.      if [ -f $OLD_LOGFILE.1 ]; then
  118.         cat $OLD_LOGFILE.1;
  119.      elif [ -f $OLD_LOGFILE.1$Z_DOT ]; then
  120.         $ZCAT $OLD_LOGFILE.1$Z_DOT;
  121.      fi) | sed ":l1
  122.             /^[^|].*\[m$f\]/{
  123.             :l2
  124.             s/^/  /
  125.             n
  126.             /^|/!b l1
  127.             s/^|    /|       /
  128.             b l2
  129.             }
  130.             d"
  131.     echo ""; echo "Paniclog entries related to this messsage are:"
  132.     (if [ -f $PANICLOG ]; then
  133.         cat $PANICLOG;
  134.      fi
  135.      if [ -f $OLD_PANICLOG.0 ]; then
  136.         cat $OLD_PANICLOG.0;
  137.      elif [ -f $OLD_PANICLOG.0$Z_DOT ]; then
  138.         $ZCAT $OLD_PANICLOG.0$Z_DOT;
  139.      fi
  140.      if [ -f $OLD_PANICLOG.1 ]; then
  141.         cat $OLD_PANICLOG.1;
  142.      elif [ -f $OLD_PANICLOG.1$Z_DOT ]; then
  143.         $ZCAT $OLD_PANICLOG.1$Z_DOT;
  144.      fi) |    grep "\[m$f\]" | sed 's/^/  /'
  145.     done > .newerrors
  146.  
  147.     mv .newerrors .checkerror
  148.  
  149.     if [ -s .checkerror ]; then
  150.     # don't send to the Postmaster if configuration errors still exist
  151.     x="`$SMAIL_PROGRAM -bv Postmaster 2>/dev/null`"
  152.     if [ "$x" ]; then
  153.         $SMAIL_PROGRAM -f"<+>" -eq -m Postmaster <<EOF
  154. From: MAILER-DAEMON
  155. Subject: Mail errors on the host $HOSTNAME
  156.  
  157. Smail has detected new errors requiring your attention on the
  158. host $HOSTNAME.  Messages which failed can be found in the
  159. directory $SPOOLDIR/error and should be moved back to
  160. $SPOOLDIR when the situation which caused the error has
  161. been taken care of.
  162.  
  163. A sumary of these errors follows:
  164.  
  165. `cat .checkerror`
  166. EOF
  167.         if [ $? -eq 0 ]; then
  168.         rm -f .checkerror
  169.         fi
  170.     fi
  171.     fi
  172. done
  173.  
  174. exit 0
  175.